import React from 'react';
import {Router, Route, Switch} from 'dva/router';
import dynamic from 'dva/dynamic';
import RouterConfig from './config/routes';
import APP from './routes/index'
import NotFound from './routes/404'
import TabBar from "./components/layout/tabBar"


// 把路由组件暴露
export default ({history, app}) => {

  let isShow = true,
    pathname = history.location.pathname.substring(1);

  if (history.location.pathname == '/') {
    window.localStorage.setItem("tabBarName", "index");
  }

  switch (pathname) {
    case "login":
      isShow = false;
      break;
    default:
      isShow = true;
      break;
  }

  console.log(pathname);


  return (
    <Router history={history}>
      <div className={'root'}>
        <Switch>
          {/* 首页 */}
          <Route path="/" exact component={APP}/>
          {/* 其他页面 */}
          {
            RouterConfig.map(({path, ...dynamics}, index) => {
              return (
                <Route
                  key={index}
                  path={path}
                  exact
                  component={
                    dynamic({
                      app,
                      ...dynamics
                    })
                  }
                />
              )
            })
          }

          {/* 404页面 */}
          <Route exact component={NotFound}/>
        </Switch>
        {/* 页面底部 */}
        <TabBar isShow={!isShow} history={history}/>
      </div>
    </Router>
  )
}